<?php
// 享元模式 注册机模式

interface FlyWeight {public function operation();}

class MyFlyWeight implements FlyWeight
{
	public function operation()
	{

	}
}

class FlyWeightFactory
{
	protected static $flyWeightPool;

	public function __construct()
	{
		if (!isset(self::$flyWeightPool)) {
			self::$flyWeightPool = [];
		}
	}

	public function getFlyWeight($flyWeight)
	{
		if (array_key_exists($flyWeight, self::$flyWeightPool)) {
			return self::$flyWeightPool[$flyWeight];
		} else {
			$myFlyWeight = new $flyWeight;
			self::$flyWeightPool[] = $myFlyWeight;
			return $myFlyWeight;
		}
	}
}